﻿using TTQT.TTQT_Code.Info;

namespace TTQT
{
	/// <summary>
	/// Summary description for MasterControl.
	/// </summary>
	public class PublicMasterControl:System.Web.UI.UserControl
	{
		public string brnCode
		{
			get
			{
				if(null !=Session["Brn_Code"])
				{
					return Session["Brn_Code"].ToString();
				}
				else
				{
					return string.Empty;
				}
			}
		}
	    public UserInfo UserInfo
	    {
	        get
	        {
	            try
	            {
                    return (UserInfo) Session["UserInfo"];
	            }catch
	            {
	                return new UserInfo();
	            }
	        }
	    }
		public string userId
		{
			get
			{
				if(null !=Session["UserId"])
				{
					return Session["UserId"].ToString();
				}
				else
				{
					return string.Empty;
				}
			}
		}
		public string userName
		{
			get
			{
				if(null !=Session["UserName"])
				{
					return Session["UserName"].ToString();
				}
				else
				{
					return string.Empty;
				}
			}
		}
		public string isSuperAdmin
		{
			get
			{
				if(null !=Session["IsSuperAdmin"])
				{
					return Session["IsSuperAdmin"].ToString();
				}
				else
				{
					return string.Empty;
				}
			}
		}

		public bool isCNN
		{
			get
			{
				if(null!=Session["CNN"])
				{
					if(Session["CNN"].ToString().Equals("0"))
					{
						return false;
					}
					else if(Session["CNN"].ToString().Equals("1"))
					{
						return true;
					} 
				}
				else
				{
					return false;
				}
				return false;
			}
		}

		public bool isTTQT
		{
			get
			{
				if(null!=Session["TTQT"])
				{
					if(Session["TTQT"].ToString().Equals("0"))
					{
						return false;
					}
					else if(Session["TTQT"].ToString().Equals("1"))
					{
						return true;
					} 
				}
				else
				{
					return false;
				}
				return false;
			}
		}
		public bool isBranchManager
		{
			get 
			{
				if(null!=Session["GroupId"])
				{
					if(Session["GroupId"].ToString().Equals("1"))
					{
						return true;
					}
				}
				return false;
			}
		}
		public bool isKSV
		{
			get 
			{
				if(null!=Session["GroupId"])
				{
					if(Session["GroupId"].ToString().Equals("2"))
					{
						return true;
					}
				}
				return false;
			}
		}
		public bool isTTV
		{
			get 
			{
				if(null!=Session["GroupId"])
				{
					if(Session["GroupId"].ToString().Equals("3"))
					{
						return true;
					}
				}
				return false;
			}
		}
		public bool isRole(string group_name)
		{
			try
			{
				return Session["group_names"].ToString().ToLower().IndexOf(group_name.ToLower()) > 0;
			}
			catch
			{
				return false;
			}
		}
		public string appHomeUrl()
		{
			string fullUrl = Request.Url.ToString();
			if(fullUrl.IndexOf("/")>0)
			{
				return fullUrl.Substring(0, fullUrl.LastIndexOf("/")+1);
			}
			else
				return "";
		}
		public string navigateUrl(int pageId)
		{
			return appHomeUrl()+ "Default.aspx?pageId="+pageId.ToString();
		}
		public string navigateUrl(int pageId,string tenThamSo, string giaTriThamSo)
		{
			return appHomeUrl()+ "Default.aspx?pageId="+pageId.ToString()+"&"+tenThamSo+"="+giaTriThamSo;
		}
	}
}
